#include <iostream>
#include <memory>
using namespace std;
class Person
{
public:
    Person()
    {
        cout<<"Person()"<<endl;
    }
    ~Person()
    {
        cout<<"~Person()"<<endl;
    }
public:
    void run()
    {
        cout<<"person run()"<<endl;
    }
private:
    int m_age;
};

template<typename T>
class smartPtr
{
public:
    smartPtr(T * obj)
    {
        ptr = obj;
        // cout<<"smartPtr()"<<endl;
    }
    ~smartPtr()
    {
        delete ptr;
        // cout<<"~smartPtr()"<<endl;
    }

public:
    T * operator->()
    {
        return ptr;
    }
private:
    T * ptr;

};

int main()
{
    // {
    //     Person * p2 = new Person;
    //     p2->run();
    //     /*只有调用delete才会调用析构*/
    //     delete p2;
    // }
#if 0
    {
        /*auto_ptr 的使用*/
        auto_ptr<Person> p1(new Person);
        p1->run();
    }
#endif
    smartPtr<Person> sp(new Person);
    sp->run();
    return 0;
}